package com.mlnx.work.service.iml;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mlnx.common.form.PageForm;
import com.mlnx.work.dao.mysql.DepartmentMapper;
import com.mlnx.work.entity.Department;
import com.mlnx.work.pojo.form.DepartmentFilterForm;
import com.mlnx.work.pojo.vo.SelfDepartmentVo;
import com.mlnx.work.service.DepartmentService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * author name: amanda.shan
 * create time: 2020-12-28 16:58:01
 */
@Service
public class DepartmentServiceIml extends BaseService<DepartmentMapper, Department> implements DepartmentService {

    @Autowired
    @Override
    public void setBaseMapper(DepartmentMapper baseMapper) {
        super.setBaseMapper(baseMapper);
    }

    @Override
    public IPage page(PageForm pageForm, Object filter) throws IllegalAccessException {
        return baseMapper.listDepartmentVo(new Page<>(pageForm.getCurrent(), pageForm.getSize()), (DepartmentFilterForm) filter);
    }

    @Override
    public void renewCount(Integer id, Integer count) {

        Department department = new Department();
        department.setNumb(count);
        department.setId(id);

        updateById(department);
    }

    @Override
    public Department getDeptByTask(Integer taskId) {
        return baseMapper.selectByTaskId(taskId);
    }

    @Override
    public SelfDepartmentVo getSelfDepartment() {

        Integer selfDeptId = getSelfDeptId();

        return baseMapper.selectDepartmentVo(selfDeptId);
    }
}

